import { Body, Query, Controller, Get, Post, Req, Res, Param, Module, Put, Delete } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { UseGuards } from '@nestjs/common'
import { MenusService } from '../menus/menus.service'
import { Menus } from '../entity/menus.entity'
import { PageInit, PageNation } from 'src/interface/page.interface';
@Controller('menus')
export class MenusController {
    constructor(private menusRepository: MenusService) {}
    @UseGuards(JwtAuthGuard)
    @Post('create')
    async create(@Body() role: Menus) {
        try {
            return this.menusRepository.create(role)
        } catch (error) {
            return {
                code: 500,
                msg: error
            }
        }
    }

    @UseGuards(JwtAuthGuard)
    @Put('update')
    async update(@Body() menus: Menus) {
        let res = await this.menusRepository.update(menus);
        // console.log('输出返回结构：', res)
        if (res.menu_id) {
            return {
                data: '返回成功',
                code: 1000,
            }
        }else {
            return {
                data: '返回失败',
                code: 500,
            }
        }
    }

    @UseGuards(JwtAuthGuard)
    @Get('findAll')
    async findAll(@Query() query: PageInit) {
        // console.log('输出take：',query)
        let res = await this.menusRepository.findAll(query);
        return res;
    }


}


